# 
# Name: plot2eps
# Description:  Execute gnuplot scripts to create eps graphics. 
#               Extra white space is cropped.
# Author: Wilson Santos, 36228 <wilson.santos@ua.pt>
#
function epscrop {
# Remove plot white margin
tmp="tmp.eps"
eps2eps "$1" "$tmp"
sedop="s/$(cat "$1" | grep %%BoundingBox)/$(cat "$tmp" | grep %%BoundingBox)/g"
sed -e"$sedop" "$1" > croped.eps
rm "$tmp" "$1"
mv croped.eps "$1"
}

# ------------ MAIN ------------ #
cd images/results/

# Create plots
for gnu in $(ls *.gnu); do
  echo "$gnu"" --> ""${gnu%.gnu}".eps
  gnuplot "$gnu"

  epscrop "${gnu%.gnu}".eps
done
